import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
from pymoo.indicators.hv import HV


def generate_points(lo=0, hi=1, N=10):
    return np.column_stack((np.random.uniform(lo, hi, N), np.random.uniform(lo, hi, N)))


def plot_points(points):
    # 将数据转换为 DataFrame
    data = pd.DataFrame({"x": points[:, 0], "y": points[:, 1]})

    # 绘制散点图
    sns.set_theme(style="whitegrid")
    sns.scatterplot(
        data=data,
        x="x",
        y="y",
        color="blue"
    )

    # 设置图表标题和标签
    plt.title(f"Scatter Plot of Random Points")
    plt.xlim(-0.1, 1.2)
    plt.ylim(-0.1, 1.2)
    plt.show()


def normalize(points):
    normalized_points = np.copy(points)
    point_max, point_min = np.max(normalized_points, axis=0), np.min(
        normalized_points, axis=0
    )
    for i in range(len(normalized_points)):
        normalized_points[i][0] = (normalized_points[i][0]) / (
            1 * (point_max[0] - point_min[0])
        )
        normalized_points[i][1] = (normalized_points[i][1]) / (
            1 * (point_max[1] - point_min[1])
        )
    return normalized_points


def calculate_hv(points, ref_point=[1.2, 1.2]):
    hv = HV(ref_point=ref_point)
    return hv(points)


# 生成随机点
points = generate_points(lo=1, hi=100, N=100)

# 对点进行规范化
normalized_points = normalize(points)

# 计算HV
print(calculate_hv(normalized_points))

# 绘制规范化后的散点图
plot_points(normalized_points)
